package com.bjpowernode.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 封装统一的返回结果对象
 *
 * 只要是返回给前端，通通用这个类来返回
 */
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class R {

    //返回的状态码（结果码）
    private int code;

    //返回的结果信息
    private String msg;

    //返回的结果数据
    private Object data;

    public static R OK() {
        return R.builder().code(ResultEnum.OK.getCode()).msg(ResultEnum.OK.getMsg()).build();
    }

    public static R OK(Object data) {
        return R.builder().code(ResultEnum.OK.getCode()).msg(ResultEnum.OK.getMsg()).data(data).build();
    }

    public static R FAIL() {
        return R.builder().code(ResultEnum.FAIL.getCode()).msg(ResultEnum.FAIL.getMsg()).build();
    }

    public static R FAIL(String msg) {
        return R.builder().code(ResultEnum.FAIL.getCode()).msg(msg).build();
    }
}
